using System;
using Microsoft.Xna.Framework;

namespace CellarDoor.Gui
{
    /// <summary>
    /// A simple padding struct that holds sizes for Top, Bottom, Left and Right distance
    /// </summary>
    [System.Diagnostics.DebuggerDisplay("{Top} {Right} {Bottom} {Left}")]
    public struct UiPadding
    {
        public static UiPadding Zero = new UiPadding();

        public int Top;
        public int Bottom;
        public int Left;
        public int Right;

        /// <summary>
        /// Sets all values to same size
        /// </summary>
        public int All
        {
            set { Top = Bottom = Left = Right = value; }
        }

        /// <summary>
        /// Creates a new padding struct initialized to specified values.
        /// </summary>
        /// <param name="Top"></param>
        /// <param name="Bottom"></param>
        /// <param name="Left"></param>
        /// <param name="Right"></param>
        public UiPadding(int Top, int Bottom, int Left, int Right)
        {
            this.Top = Top;
            this.Bottom = Bottom;
            this.Left = Left;
            this.Right = Right;
        }

        /// <summary>
        /// Creates a new padding struct with all variables set to specified value.
        /// </summary>
        /// <param name="All"></param>
        public UiPadding(int All)
        {
            this.Top = All;
            this.Bottom = All;
            this.Left = All;
            this.Right = All;
        }

        public static bool operator ==(UiPadding a, UiPadding b)
        {
            return a.Top == b.Top && a.Bottom == b.Bottom && a.Left == b.Left && a.Right == b.Right;
        }

        public static bool operator !=(UiPadding a, UiPadding b)
        {
            return !(a == b);
        }

        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public UiPadding MaxMerge( UiPadding b)
        {
            return new UiPadding()
            {
                Top = Math.Max(this.Top, b.Top),
                Bottom = Math.Max(this.Bottom, b.Bottom),
                Left = Math.Max(this.Left, b.Left),
                Right = Math.Max(this.Right, b.Right)
            };
        }

        public UiPadding MinMerge(UiPadding b)
        {
            return new UiPadding()
            {
                Top = Math.Min(this.Top, b.Top),
                Bottom = Math.Min(this.Bottom, b.Bottom),
                Left = Math.Min(this.Left, b.Left),
                Right = Math.Min(this.Right, b.Right)
            };
        }

        public Rectangle InflateRectangle(Rectangle rect)
        {
            InflateRectangle(ref rect);
            return rect;
        }

        public void InflateRectangle(ref Rectangle rect)
        {
            rect.X -= Left;
            rect.Y -= Top;
            rect.Width += (Left + Right);
            rect.Height += (Top + Bottom);
        }

        public Rectangle DeflateRectangle(Rectangle rect)
        {
            DeflateRectangle(ref rect);
            return rect;
        }

        public void DeflateRectangle(ref Rectangle rect)
        {
            rect.X += Left;
            rect.Y += Top;
            rect.Width -= (Left + Right);
            rect.Height -= (Top + Bottom);
        }
    }
}
